package hk.m4s.lr.repair.test.ui.adapter;

import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.List;

import hk.m4s.lr.repair.test.R;
import hk.m4s.lr.repair.test.model.CenterCheckMainModel;
import hk.m4s.lr.repair.test.model.NewsModel;
import hk.m4s.lr.repair.test.ui.baoyang.LookBaoYangActivity;
import hk.m4s.lr.repair.test.ui.baoyang.LookRepaireActivity;

/**
 * Created by qi.wang on 2017/3/16.
 */

public class BaoYangListAdapter extends BaseAdapter {
    List<CenterCheckMainModel> list = new ArrayList<>();
    Context context;
    LayoutInflater inflater;

    public BaoYangListAdapter(Context context, List<CenterCheckMainModel> data) {
        this.context = context;
        this.list = data;
        inflater = LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if (convertView == null) {
            holder = new ViewHolder();
            convertView = inflater.inflate(R.layout.list_item_baoyang, parent, false);
            holder.baoyang_title = (TextView) convertView.findViewById(R.id.baoyang_title);
            holder.baoyang_content = (TextView) convertView.findViewById(R.id.baoyang_content);
            holder.baoyang_time = (TextView) convertView.findViewById(R.id.baoyang_time);
            holder.by_looks = (TextView) convertView.findViewById(R.id.by_looks);
            holder.nby_types = (TextView) convertView.findViewById(R.id.nby_types);
            holder.looks_lay = (LinearLayout) convertView.findViewById(R.id.looks_lay);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        holder.looks_lay.setTag(position);
        holder.by_looks.setTag(position);
        if (list != null && list.size() > 0) {
            CenterCheckMainModel model = list.get(position);
            holder.baoyang_title.setText(model.getName());
            holder.baoyang_time.setText(model.getDay());
            holder.baoyang_content.setText(model.getMsg());
            holder.by_looks.setText("未完成  " + model.getNoNum());
            holder.nby_types.setText("已完成  " + model.getYesNum());
            try {
                // Glide.with(context).load(businessModel.getImages1()).asBitmap().into(holder.business_image);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        holder.by_looks.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                int num = (Integer) v.getTag();
                CenterCheckMainModel model = list.get(num);
                Intent intent = null;
                if(model.getType().equals("3")){
                    intent = new Intent(context, LookRepaireActivity.class);
                }else{
                    intent = new Intent(context, LookBaoYangActivity.class);
                }
                intent.putExtra("type", model.getType());
                intent.putExtra("name",model.getName());
                intent.putExtra("state", "-1");
                context.startActivity(intent);
            }
        });
        holder.looks_lay.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                int num = (Integer) v.getTag();
                CenterCheckMainModel model = list.get(num);
                Intent intent = null;
                if(model.getType().equals("3")){
                    intent = new Intent(context, LookRepaireActivity.class);
                }else{
                    intent = new Intent(context, LookBaoYangActivity.class);
                }
                intent.putExtra("type", model.getType());
                intent.putExtra("name",model.getName());
                intent.putExtra("state", "1");
                context.startActivity(intent);
            }
        });
        return convertView;
    }

    public static class ViewHolder {
        TextView baoyang_title;
        TextView baoyang_content;
        TextView baoyang_time;
        TextView by_looks;
        TextView nby_types;
        private LinearLayout looks_lay;
    }
}
